<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="商标名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandName">
              <a-input v-model="model.brandName" placeholder="请输入商标名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商标标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandLabel">
              <a-input v-model="model.brandLabel" placeholder="请输入商标标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商标类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandType">
              <a-input v-model="model.brandType" placeholder="请输入商标类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商标价值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandValue">
              <a-input v-model="model.brandValue" placeholder="请输入商标价值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="国际分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="internationalClass">
              <a-input v-model="model.internationalClass" placeholder="请输入国际分类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商标状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入商标状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请号/注册号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationNo">
              <a-input v-model="model.applicationNo" placeholder="请输入申请号/注册号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="初审日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firstInstanceTime">
              <j-date placeholder="请选择初审日期" v-model="model.firstInstanceTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册公告日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registerTime">
              <j-date placeholder="请选择注册公告日期" v-model="model.registerTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="版本号乐观锁" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="version">
              <a-input-number v-model="model.version" placeholder="请输入版本号乐观锁" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="修改时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastTime">
              <j-date placeholder="请选择修改时间" v-model="model.lastTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="修改人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastUser">
              <a-input v-model="model.lastUser" placeholder="请输入修改人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createUser">
              <a-input v-model="model.createUser" placeholder="请输入创建人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createUserId">
              <a-input v-model="model.createUserId" placeholder="请输入创建人账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="修改人账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastUserId">
              <a-input v-model="model.lastUserId" placeholder="请输入修改人账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否应续展1是" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isExtension">
              <a-input v-model="model.isExtension" placeholder="请输入是否应续展1是"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationName">
              <a-input v-model="model.applicationName" placeholder="请输入申请人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际权属主体" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainBody">
              <a-input v-model="model.mainBody" placeholder="请输入实际权属主体"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="代理机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="agency">
              <a-input v-model="model.agency" placeholder="请输入代理机构"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="权利证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="letterOfAuthorization">
              <a-input v-model="model.letterOfAuthorization" placeholder="请输入权利证书"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商标图样" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="picture">
              <a-input v-model="model.picture" placeholder="请输入商标图样"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationTime">
              <j-date placeholder="请选择申请日期" v-model="model.applicationTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除标识1是" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDel">
              <a-input v-model="model.isDel" placeholder="请输入删除标识1是"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="专用权期限日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="termTime">
              <j-date placeholder="请选择专用权期限日期" v-model="model.termTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BrandForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           brandName: [
              { required: true, message: '请输入商标名称!'},
           ],
           brandType: [
              { required: true, message: '请输入商标类型!'},
           ],
           brandValue: [
              { required: true, message: '请输入商标价值!'},
           ],
            applicationNo: [
              { required: true, message: '请输入申请号/注册号!'},
           ],
        },
        url: {
          add: "/knowledge/brand/add",
          edit: "/knowledge/brand/edit",
          queryById: "/knowledge/brand/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>